package business.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Required;
import org.springframework.transaction.annotation.Transactional;

import vo.Element;
import business.ElementService;
import dao.ElementDAO;

public class ElementServiceImpl implements ElementService{

	private ElementDAO elementDao;
	
	public List<Element> getAllElements() {
		return elementDao.findAll();
	}
	
	public List<Element> getByTemplateId(long templateId) {
		return elementDao.findByTemplateId(templateId);
	}

	public Element getByTemplateIdName(long tId,String name) {
		return elementDao.findByTemplateIdName(tId,name);
	}

	@Required
	public void setElementDao(ElementDAO elementDao) {
		this.elementDao = elementDao;
	}

	@Transactional
	public void addElement(String name) {
		Element e = new Element();
		e.setName(name);
		elementDao.create(e);
	}

	@Transactional
	public void addElement(Element e) {
		elementDao.create(e);
	}
	@Transactional
	public Element getById(long id) {
		return elementDao.getById(id);
	}

	@Transactional
	public void update(long id) {
		elementDao.update(id);
	}

	@Transactional
	public void delete(long id) {// 真正删除
		elementDao.delete(id);
	}

}